<template>
  <div>
    <input
      type="text"
      placeholder="请搜索"
      v-model="serch"
      @keydown.enter="serchkeydown()"
    />
    <button @click="ok">搜索</button>
    <ul>
      <li v-for="(item, index) of data" :key="index">
        <router-link :to="`/serch/:${item.id}`">
          <div v-if="data.length > 0">
            {{ item.title }}
            {{ item.id }}
          </div>
          <div v-else>您查找的数据为空！！</div>
        </router-link>
      </li>
    </ul>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      data: [],
      serch: ''
    }
  },
  methods: {
    serchkeydown() {
      this.getData()
    },
    ok() {
      console.log(this.serch)
      this.getData()
    },
    getData() {
      axios({
        method: 'POST',
        url: 'https://700e.com/ipfs/t-news/querys',
        data: {
          pageSize: 20,
          titleLike: this.serch
        }
      })
        .then((res) => {
          this.data = res.data.data.data
          console.log(this.data)
        })
        .catch((error) => {
          console.log(error)
        })
    }
  },
  mounted() {}
}
</script>

<style>
</style>
